import grpc
import time
from concurrent import futures
from grpc_test.base_package import data_pb2, data_pb2_grpc

_ONE_DAY_IN_SECONDS = 60 * 60 *24
_HOST = 'localhost'
_PORT = '9999'

class FormData(data_pb2_grpc.FormatDataServicer):
    # 重写接口函数
    def DoFormat(self, request, context):
        s = request.text
        return data_pb2.act_response(text=s.upper())

def Server():
    grpcServer = grpc.server(futures.ThreadPoolExecutor(max_workers=4))
    data_pb2_grpc.add_FormatDataServicer_to_server(FormData(), grpcServer)
    grpcServer.add_insecure_port(_HOST+":"+_PORT)
    grpcServer.start()
    try:
        while True:
            time.sleep(_ONE_DAY_IN_SECONDS)
    except KeyboardInterrupt:
        grpcServer.stop(0)

if __name__=='__main__':
    Server()